#ifndef USERDEFINE_H_
#define USERDEFINE_H_

#include "Cpu.h"

#define FALSE (0x00)
#define TRUE  (0x01)

/* FlexWire definition */
#define SYNC                   (0x55)

/* DEV_ADDR byte */
#define DEVICE_ADDR__0         (0x00)
#define DEVICE_ADDR__1         (0x01)
#define DEVICE_ADDR__2         (0x02)
#define DEVICE_ADDR__3         (0x03)
#define DEVICE_ADDR__4         (0x04)
#define DEVICE_ADDR__5         (0x05)
#define DEVICE_ADDR__6         (0x06)
#define DEVICE_ADDR__7         (0x07)
#define DEVICE_ADDR__8         (0x08)
#define DEVICE_ADDR__9         (0x09)
#define DEVICE_ADDR__10        (0x0A)
#define DEVICE_ADDR__11        (0x0B)
#define DEVICE_ADDR__12        (0x0C)
#define DEVICE_ADDR__13        (0x0D)
#define DEVICE_ADDR__14        (0x0E)
#define DEVICE_ADDR__15        (0x0F)

// Broadcast mode - (Bit 6)
#define BROADCAST              (0x40)      /* Broadcast (DEVICE_ADDR = 0x00) */
#define SINGLE_DEVICE_MODE     (0x00)
#define BROADCAST_MODE         (BROADCAST)
// Read/Write mode - (Bit 7)
#define READ                   (0x00)      /* Read mode */
#define WRITE                  (0x80)      /* Write mode */
#define READ_MODE              (READ)
#define WRITE_MODE             (WRITE)

// Burst mode data length - (Bit 4-5)
#define DATA_LENGTH__1         (0x00)      /* Single-byte mode with 1 byte of data */
#define DATA_LENGTH__2         (0x10)      /* Burst mode with 2 bytes of data */
#define DATA_LENGTH__4         (0x20)      /* Burst mode with 4 bytes of data */
#define DATA_LENGTH__8         (0x30)      /* Burst mode with 8 bytes of data */
#define	NORMAL_MODE            (DATA_LENGTH__1)
#define	BURST_MODE_SIZE_2      (DATA_LENGTH__2)
#define	BURST_MODE_SIZE_4      (DATA_LENGTH__4)
#define	BURST_MODE_SIZE_8      (DATA_LENGTH__8)
#define BURST_MODE_SIZE_16     (DATA_LENGTH__16)
#define BURST_MODE_SIZE_24     (DATA_LENGTH__24)
#define	DATA_LENGTH_1          (DATA_LENGTH__1)
#define	DATA_LENGTH_2          (DATA_LENGTH__2)
#define	DATA_LENGTH_4          (DATA_LENGTH__4)
#define	DATA_LENGTH_8          (DATA_LENGTH__8)
#define DATA_LENGTH_16         (DATA_LENGTH__16)
#define DATA_LENGTH_24         (DATA_LENGTH__24)
// 0 --> 1
// 1 --> 4
// 2 --> 16
// 3 --> 24
#define DATA_LENGTH(x)         (1 << (x >> 4))

// Define if CAN or UART is used
#define CAN_USED             FALSE

// When non-broadcast is transmitted, does the CRC need to be checked
#define ALWAYS_CHECK_CRC     FALSE

#define MAX_BURST_CNT 24U

#define DUTY_VALUE_MAX  0xFFFU


extern uint8_t g_sendBuffer[MAX_BURST_CNT];
extern uint8_t g_rcvBuffer[MAX_BURST_CNT];
extern uint16_t rcvCrcError;
extern uint16_t ackEnabled[DEVICE_ADDR__15 + 1];
extern uint16_t read_offset;


#endif /* USERDEFINE_H_ */
